<template>
  <dtDialog
    title="修改文件保存时间"
    :visible.sync="dialogVisible"
    :lock-scroll="false"
    :append-to-body="true"
    :is-loading="loading"
    @closeDialog="onModalClosed"
    @comfirmBtn="onSubmit()"
  >
    <el-form
      ref="form"
      slot="content"
      label-width="160px"
      :model="form"
      :rules="rules"
    >
      <el-row>
        <el-col :span="24">
          <el-form-item label="文件名">
            <span>{{ form.fileOriginName }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="文件保存当前剩余天数">
            <span>{{ form.surplusDays }}</span>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="自定义">
            <el-switch v-model="form.custom"></el-switch>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="form.custom">
          <el-form-item label="自定义保存时间" prop="customDays">
            <el-input v-model="form.customDays" placeholder="请输入保存时间"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="24" v-else>
          <el-form-item label="更新文件保存剩余天数" prop="newDay">
            <el-radio-group v-model="form.newDay">
              <el-radio :label="3">3天后删除</el-radio>
              <el-radio :label="5">5天后删除</el-radio>
              <el-radio :label="7">7天后删除</el-radio>
              <el-radio :label="15">15天后删除</el-radio>
              <el-radio :label="30">30天后删除</el-radio>
            </el-radio-group>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </dtDialog>
</template>

<script>
import { videoEdit } from '@/api/videoFusion/videoManage'

export default {
  data() {
    return {
      dialogVisible: false,
      form: {
        fileOriginName: '',
        surplusDays: '',
        newDay: '',
        customDays: '',
        custom: false
      },
      rules: {
        newDay: [{ required: true, message: '请选择保存剩余天数', trigger: ['blur', 'change'] }],
        customDays: [{ required: true, message: '请输入保存时间', trigger: ['blur'] }]
      },
      loading: false
    }
  },
  methods: {
    onModalClosed() {
      this.initModal()
      this.buttonLoading = false
    },
    initModal() {
      this.$refs.form.resetFields()
      this.form = {
        fileOriginName: '',
        surplusDays: '',
        newDay: '',
        customDays: ''
      }
    },
    onSubmit() {
      this.$refs.form.validate((result, message) => {
        if (result) {
          this.loading = true
          const data = {
            id: this.form.id,
            ids: [this.form.id],
            surplusDays: this.form.custom ? this.form.customDays : this.form.newDay
          }
          videoEdit(data).then((res) => {
            this.$emit('success')
            this.dialogVisible = false
            this.$dtModal.msgSuccess(res.message)
            this.loading = false
          }).catch(() => {
            this.loading = false
          })
        }
      })
    },
    open(row) {
      this.form = { ...row }
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
      })
    }
  }
}
</script>

<style>

</style>
